package com.humi.partner.manager.web.partner;

import com.humi.cloud.common.model.Result;
import com.humi.partner.manager.model.partnerType.PartnerTypeListQueryRequest;
import com.humi.partner.manager.service.ManagerPartnerTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.concurrent.Callable;

import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

/**
 * @Auther: lishijie
 * @Date: 2019/10/11 13:55
 * @Description:Codes are far away from bugs with the animal protecting
 */
@RestController
@RequestMapping(value = "/partner_type")
@Api(produces = APPLICATION_JSON_UTF8_VALUE, tags = "伙伴类型基础数据")
public class ManagerPartnerTypeController {

    @Autowired
    ManagerPartnerTypeService managerPartnerTypeService;

    @PostMapping("/lib/page")
    @ApiOperation(value = "分页查询伙伴类型列表",notes ="伙伴类型",response = PartnerTypeListQueryRequest.class)
    public Callable<Result> getPartnerTypeLibPage(@Valid @ApiParam @RequestBody PartnerTypeListQueryRequest request, BindingResult error){
        return () -> error.hasErrors() ? Result.argumentFail(error.getFieldError().getDefaultMessage()) : managerPartnerTypeService.getPertnerType(request);
    }
}
